<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : product.class.manage.php   FILE_PATH : D:\webroot\mulitishop\system\product.class.manage.php
 * ....商品类别管理文件
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 天津网城创想开发团队 php_netproject@yahoo.com.cn
 * @package 
 * @subpackage 
 * @version Wed Aug 08 13:42:53 CST 2007
 */

require ("../global.inc.php");

class SysProductClassManage extends SystemFrameWork{

	/**
	 * 商品分类对象
	 *
	 * @var obj
	 */
	var $objProductClass;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $objvalidate;

	/**
     * 根据参数进行商品类别的操作
     *
     * 
     */
	function main(){
		/**
		 * 加载语言包
		 */
		$this->getlang("productClass");
		/**
		 * 创建商品分类对象
		 */
		if (!is_object($this->objProductClass)){
			require_once ("productclass.class.php");
			$this->objProductClass = new ProductCategoryClass();
		}
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}
		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("system");

		switch ($this->_input['action']){
			case "manage":
				$this->_manageclass();
				break;
			case "list":
				$this->_listclass();
				break;
			case "add":
				$this->_addclass();
				break;
			case "save":
				$this->_saveclass();
				break;
			case "modi":
				$this->_modiclass();
				break;
			case "update":
				$this->_updateclass();
				break;
			case "del":
				$this->_delclass();
				break;
			case "restart":
				$this->_restartclass();
				break;
			default:
				$this->_manageclass();
				break;
		}

	}

	/**
     * 商品类别列表页面
     *
     */
	function _listclass(){
		/**
		 * 分页
		include_once("CommonPage.php");
		$Objpage   = new CommonPage();
		//$this->_configinfo[websit][site_url];
		$Objpage->pagebarnum(20);   //每页显示的数量
		*/

		$ProductClassArray = $this->objProductClass->listClassDetail($conditionstr="",$Objpage);
		$this->output("ProductClassArray",$ProductClassArray);
		$this->showpage("sys_pclass.list");

	}
	/**
     * 商品类别管理列表
     *
     */
	function _manageclass(){
		/**
		 * 分页
		include_once("CommonPage.php");
		$Objpage   = new CommonPage();
		//$this->_configinfo[websit][site_url];
		$Objpage->pagebarnum(20);   //每页显示的数量
		*/

		$ProductClassArray = $this->objProductClass->listClassDetail($conditionstr="",$Objpage);
		$this->output("ProductClassArray",$ProductClassArray);
		$this->showpage("sys_pclass.manage");

	}

	/**
	 * 显示新增分类页面
	 *
	 */
	function _addclass(){
		$ProductClassArray = $this->objProductClass->listClassDetail($conditionstr="",$Objpage);
		$this->output("slPCUId",Common::showForm_Select2("slPCUId","","",$ProductClassArray,""));
		$this->showpage("sys_pclass.add");
	}
	/**
	 * 增加商品分类
	 *
	 */
	function _saveclass(){
		/**
		 * 验证提交的数据
		 */
		$this->objvalidate->setValidate(array("input"=>$this->_input['txtPCName'],"require"=>"true","message"=>$this->_lang['errPCName']));
		$this->objvalidate->setValidate(array("input"=>$this->_input['txtPCIntro'],"require"=>"true","message"=>$this->_lang['errPCIntro']));
		$error = $this->objvalidate->validate();
		if ($error != ""){
			echo $error;
		}else{
			$this->objProductClass->addProductClass($this->_input);
			@header("location:pclass.manage.php?action=add");
		}

	}
	/**
	 * 编辑分类页面
	 *
	 */
	function _modiclass(){
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["pcid"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errPClassId']));
		$error = $this->objvalidate->validate();
		if($error != ""){
			echo $error;
		}else{
			$pclass_array = $this->objProductClass->getPClassRow($this->_input["pcid"]);
			$ProductClassArray = $this->objProductClass->listClassDetail($conditionstr="",$Objpage);
			$this->output("pclass_array",$pclass_array);
			$this->output("slPCUId",Common::showForm_Select2("slPCUId","","",$ProductClassArray,$pclass_array['pc_u_id']));
			$this->showpage("sys_pclass.add");
			echo "ok";
		}

	}
	/**
	 * 更新商品分类
	 *
	 */
	function _updateclass(){
		/**
		 * 商品品分类状态暂时默认为1发布
		 */
		$this->_input["txtPCState"] = 1;
		/**
		 * 验证表单信息
		 */
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["txtPCId"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errPCId']),
		array("input"=>$this->_input["txtPCName"],"require"=>"true","message"=>$this->_lang['errPCName']),
		array("input"=>$this->_input["slPCUId"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errPCUId']),
		array("input"=>$this->_input["txtPCIntro"],"require"=>"true","message"=>$this->_lang['errPCIntro']));
		$error = $this->objvalidate->validate();
		if($error != ""){
			echo $error;
		}else{
			$result = $this->objProductClass->updateProductClass($this->_input);
			$result = $this->_restartclass();
			echo "ok";
		}
	}
	/**
	 * 删除商品分类操作
	 */
	function _delclass(){
		/**
		 * 验证表单信息
		 */
		foreach ($this->_input['chboxPCId'] as $value){
			$this->objvalidate->setValidate(array("input"=>$value,"validator"=>"Number","message"=>$this->_lang['errPCId']));
		}
		$error = $this->objvalidate->validate();
		if($error != ""){
			echo $error;
		}else{
			$result = $this->objProductClass->delProductClass($this->_input['chboxPCId']);
			$result = $this->_restartclass();
			echo "ok";
		}
	}
	/**
	 * 重新生成商品分类
	 *
	 */
	function _restartclass(){
		$this->objProductClass->restartClass();
	}

}
$product_class_manage = new SysProductClassManage();
$product_class_manage->main();
unset($product_class_manage);
?>